/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "gpi_kpi_instance")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "GpiKpiInstance.findAll", query = "SELECT g FROM GpiKpiInstance g"),
    @NamedQuery(name = "GpiKpiInstance.findById", query = "SELECT g FROM GpiKpiInstance g WHERE g.gpiKpiInstancePK.id = :id"),
    @NamedQuery(name = "GpiKpiInstance.findByPosition", query = "SELECT g FROM GpiKpiInstance g WHERE g.gpiKpiInstancePK.position = :position")})
public class GpiKpiInstance implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected GpiKpiInstancePK gpiKpiInstancePK;
    @JoinColumn(name = "Id_SensorType", referencedColumnName = "ID")
    @ManyToOne
    private SensorType idSensorType;
    @JoinColumn(name = "Id_GPI_KPI", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private GpiKpi idGPIKPI;
    @JoinColumn(name = "Id_Referred_GPI_KPI", referencedColumnName = "ID")
    @ManyToOne
    private GpiKpi idReferredGPIKPI;
    @JoinColumn(name = "Id_Component", referencedColumnName = "ID")
    @ManyToOne
    private Component idComponent;

    public GpiKpiInstance() {
    }

    public GpiKpiInstance(GpiKpiInstancePK gpiKpiInstancePK) {
        this.gpiKpiInstancePK = gpiKpiInstancePK;
    }

    public GpiKpiInstance(String id, int position) {
        this.gpiKpiInstancePK = new GpiKpiInstancePK(id, position);
    }

    public GpiKpiInstancePK getGpiKpiInstancePK() {
        return gpiKpiInstancePK;
    }

    public void setGpiKpiInstancePK(GpiKpiInstancePK gpiKpiInstancePK) {
        this.gpiKpiInstancePK = gpiKpiInstancePK;
    }

    public SensorType getIdSensorType() {
        return idSensorType;
    }

    public void setIdSensorType(SensorType idSensorType) {
        this.idSensorType = idSensorType;
    }

    public GpiKpi getIdGPIKPI() {
        return idGPIKPI;
    }

    public void setIdGPIKPI(GpiKpi idGPIKPI) {
        this.idGPIKPI = idGPIKPI;
    }

    public GpiKpi getIdReferredGPIKPI() {
        return idReferredGPIKPI;
    }

    public void setIdReferredGPIKPI(GpiKpi idReferredGPIKPI) {
        this.idReferredGPIKPI = idReferredGPIKPI;
    }

    public Component getIdComponent() {
        return idComponent;
    }

    public void setIdComponent(Component idComponent) {
        this.idComponent = idComponent;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (gpiKpiInstancePK != null ? gpiKpiInstancePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof GpiKpiInstance)) {
            return false;
        }
        GpiKpiInstance other = (GpiKpiInstance) object;
        if ((this.gpiKpiInstancePK == null && other.gpiKpiInstancePK != null) || (this.gpiKpiInstancePK != null && !this.gpiKpiInstancePK.equals(other.gpiKpiInstancePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.GpiKpiInstance[ gpiKpiInstancePK=" + gpiKpiInstancePK + " ]";
    }
    
}
